#include <bits/stdc++.h>

using namespace std;

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

int main() {
    int n(read<int>()), q(read<int>());
    vector<list<int>> L(n, list<int>());
    while (q--) {
        int op(read<int>());
        if (op == 0) {
            int t = read<int>(), x = read<int>();
            L[t].push_back(x);
        } else if (op == 1) {
            int t = read<int>();
            for (auto e:L[t])cout << e << " ";
            cout << endl;
        } else if (op == 2) {
            int s = read<int>(), t = read<int>();
            L[t].splice(L[t].end(), L[s]);
        }
    }
    return 0;
}